/*!
 * @file gfxEnv.cpp
 * @brief Ciało gfxEnv.hh
 */

#include "engine/gfx/gfxEnv.hh"
using namespace std;

/*--------------------------------------------------------------------------*/

gfxEnv::gfxEnv() {
	/*
	 * Zasięg i kąt widzenia
	 */
	this->visualRange = 500.0f;
	this->fieldOfView = 60.0f;

	/*
	 * Światło rozproszone
	 */
	this->lightDiffuseSource = point3f(1.0, 1.0, 1.0);
	this->lightDiffuseSource.normalize();

	this->lightDiffuseColor = color(1.0, 1.0, 1.0);

	/*
	 * Światło otaczające
	 */
	this->lightAmbientColor = color(1.0, 1.0, 1.0);

	/*
	 * Kamera
	 */
	this->cameraPos = point3f(100.0, 100.0, 100.0);
	this->cameraVec = point3f(0.0, 0.0, 0.0);



	/*
	 * Mgła
	 */
	this->skyColor1 = color(0.15f, 0.41f, 0.72f, 1.0f);
	this->skyColor2 = color(0.45f, 0.75f, 0.98f, 1.0f);

	this->fogLength = 50.0f;

	this->waterLevel = 20.0f;

	this->gravityAcc = -9.81f;

	this->ambientToDiffuseStrength = 0.2;
}

/*--------------------------------------------------------------------------*/

void gfxEnv::startLights() {
	/*
	 * GL_LIGHT0 = słońce
	 */
	glEnable(GL_LIGHTING);

	glEnable(GL_LIGHT0);

	float diffuseColor0[] = { this->lightDiffuseColor.r,
			this->lightDiffuseColor.g, this->lightDiffuseColor.b,
			this->lightDiffuseColor.a };
	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseColor0);

	float diffusePos0[] = { this->lightDiffuseSource.x,
			this->lightDiffuseSource.y, this->lightDiffuseSource.z, 0.0 };
	glLightfv(GL_LIGHT0, GL_POSITION, diffusePos0);

	float ambientColor0[] = { this->lightAmbientColor.r,
			this->lightAmbientColor.g, this->lightAmbientColor.b,
			this->lightAmbientColor.a };
	glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor0);

}

/*--------------------------------------------------------------------------*/

void gfxEnv::stopLights() {
	glDisable(GL_LIGHTING);
}

/*--------------------------------------------------------------------------*/

void gfxEnv::addEnvUniforms(shader *sh) {

	sh->addUniformf(string("env_cameraPos"), &this->cameraPos.x,
			&this->cameraPos.y, &this->cameraPos.z);

	sh->addUniformf(string("env_fieldOfView"), &this->fieldOfView);

	sh->addUniformf(string("env_visualRange"), &this->visualRange);

	sh->addUniformf(string("env_fogLength"), &this->fogLength);

	sh->addUniformf(string("env_waterLevel"), &this->waterLevel);

	sh->addUniformf(string("env_ambientToDiffuseStrength"), &this->ambientToDiffuseStrength);

	sh->addUniformf(string("env_skyColor1"), &this->skyColor1.r,
			&this->skyColor1.g, &this->skyColor1.b);

	sh->addUniformf(string("env_skyColor2"), &this->skyColor2.r,
			&this->skyColor2.g, &this->skyColor2.b);

	sh->addUniformf("env_screenSize", pawirr::graphic->resX, pawirr::graphic->resY);
}
